<?php
namespace App\Service;

use Illuminate\Support\Facades\DB;

class BaseService
{
    //基础类

    protected static $db;
    protected static $dbVisit = 'user_visit'; //游客
    protected static $dbWx = 'user_wx'; //微信用户
    protected static $dbArea = 'area'; //省市区
    protected static $dbShequ = 'area_shequ'; //社区
    protected static $dbXcxMenu = 'xcx_menu'; //小程序底部菜单
    protected static $dbCate = 'cate'; //分类
    protected static $dbBanner = 'banner'; //轮播图
    protected static $dbQr = 'qrcode'; //码
    protected static $dbQrlog = 'qr_log'; //扫码记录
    protected static $dbH5view = 'xcx_toview'; //H5到小程序
    //个人码
    protected static $dbYwTmp = 'yw_tmp';
    protected static $dbAttr = 'yw_attr'; //更多属性
    protected static $dbImgTmp = 'img_tmp'; //临时图片
    protected static $dbAddress = 'user_address'; //用户收货地址
    //商业
    protected static $dbYwShop = 'yw_shop'; //门店
    protected static $dbUserShop = 'user_shop'; //用户门店
    protected static $dbYwGoods = 'yw_goods'; //商品
    protected static $dbYwFuwu = 'yw_fuwu'; //服务
    protected static $dbYwGorder = 'ywg_order'; //商品订单
    protected static $dbYwFworder = 'ywfw_order'; //服务订单
    //广告
    protected static $dbAd = 'ad_list'; //广告管理
    protected static $dbAdUsed = 'ad_used'; //已展示

    protected static $cateTypes = [
         '所有', '个人码', '路边小店', '跑腿服务',
    ];

    //连接数据库
    public static function dbConn($db)
    {
        return DB::connection('mysql')->table($db);
    }

    //返回格式
    public static function toback($code = 0, $msg = '', $data = [], $total = 0)
    {
        $msg = $msg ? $msg : '成功';
        return [
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
            'total' => $total,
        ];
    }

    public static function cateTypes()
    {
        $arys = [];
        $res = self::$cateTypes;
        foreach ($res as $k => $v) {
            if ($k) {
                $arys[] = [
                    'id' => $k, 'title' => $v,
                ];
            }
        }
        return $arys;
    }
}